package com.xing.poi_dome.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xing.poi_dome.dao.PoiDao;
import com.xing.poi_dome.entity.PoiEntity;
import com.xing.poi_dome.service.PoiService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @version 1.0
 * @Author Xing
 * @Date 2024/7/8 15:50
 */
@Service
public class PoiServiceimpl extends ServiceImpl<PoiDao, PoiEntity> implements PoiService {
    @Autowired
    private PoiDao dao;


    QueryWrapper<PoiEntity> query(Map<String, Object> params) {
        QueryWrapper<PoiEntity> query = new QueryWrapper<>();
        String name = (String) params.get("name");
        query.like(StringUtils.isNoneBlank(name), "name", name);
        return query;
    }

    @Override
    public IPage<PoiEntity> Page(Map<String, Object> params) {
        int page = Integer.parseInt((String) params.get("page"));
        int size = Integer.parseInt((String) params.get("size"));
        IPage<PoiEntity> iPage = new Page<>(page, size);
        IPage<PoiEntity> poiEntityIPage = dao.selectPage(iPage, query(params));
        return poiEntityIPage;
    }
}
